<template>
	<!-- 课前预习知识点 -->
	<page-body>
		<view class="page">
			<view class="flex benben-position-layout flex flex-wrap align-center flex_0_ibhf"
				:style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx', }">
				<view class='flex flex-wrap align-center justify-between flex-sub fd0_0_ibhf'>
					<view class='flex flex-wrap align-center fd0_0_c0_ibhf' @tap.stop="handleJumpDiy" data-type="back"
						data-url="1">
						<text class='fu-iconfont2  fd0_0_c0_c0_ibhf'>&#xE794;</text>
					</view>
					<view class='flex flex-wrap align-stretch justify-center'>
						<text class='fd0_0_c1_c0_ibhf'>{{classhourName}}</text>
					</view>
					<view class='flex flex-wrap align-center justify-end fd0_0_c0_ibhf'>
					</view>
				</view>

			</view>
			<view :style="{height: (88+StatusBarRpx)+'rpx'}"></view>
			<view class='flex flex-wrap align-center justify-between' style="margin: 24rpx 0;">
				<view style="margin-left: 24rpx;">
					<text class='MyPortrayal_fd1_0_c0_c1'>预习知识点</text>
					<view class='flex  MyPortrayal_fd1_0_c0_c0'></view>
				</view>
			
			</view>
			<view class=" prepare_flex_2" >	
				<view class='flex flex-direction flex-wrap align-stretch fd2_0_ibhf' v-for="(item,index) in list" :key="index" v-if="list.length>0 && isup">
				    <view class='flex flex-direction align-stretch fd2_0_c0_ibhf'>
				        <view class='flex flex-wrap align-center'>
				            <text class='fd2_0_c0_c0_c0_ibhf'>{{item.knowledgepoints_title}}</text>
				        </view>
				        <view class='flex flex-wrap align-center fd2_0_c0_c1_ibhf'>
				            <view class='flex flex-wrap align-center'>
				                <text>难易程度：</text>
				            </view>
				            <view class='flex flex-wrap align-center'>
				                <view class='flex flex-wrap align-center'>
				                    <template v-for="starNum in [1,2,3,4,5]">
				                        <image v-if="item.ny >= starNum" :key="starNum" class='star1fd2_0_c0_c1_c1_c0_ibhf' mode="aspectFit" :src='STATIC_URL+"428.png"'></image>
				                        <image v-else :key="starNum" class='star1fd2_0_c0_c1_c1_c0_ibhf' mode="aspectFit" :src='STATIC_URL+"294.png"'></image>
				                    </template>
				                </view>
				            </view>
				        </view>
				        <view class='flex flex-wrap align-center fd2_0_c0_c1_ibhf'>
				            <view class='flex flex-wrap align-center'>
				                <text>掌握程度：</text>
				            </view>
				            <view class='flex flex-wrap align-center'>
				                <view class='flex flex-wrap align-center'>
				                    <template v-for="starNum in [1,2,3,4,5]">
				                        <image v-if="item.mastery_level >= starNum" :key="starNum" class='star1fd2_0_c0_c1_c1_c0_ibhf' mode="aspectFit" :src='STATIC_URL+"428.png"'></image>
				                        <image v-else :key="starNum" class='star1fd2_0_c0_c1_c1_c0_ibhf' mode="aspectFit" :src='STATIC_URL+"294.png"'></image>
				                    </template>
				                </view>
				            </view>
				        </view>
				    </view>
				    <view class='flex flex-wrap align-center fd2_0_c1_ibhf' @tap.stop="jump(item)">
				        <text>学习资源</text>
				        <text class='fd2_0_c1_c1_ibhf'>学习进度：</text>
				        <text class='fd2_0_c1_c2_ibhf'>{{item.zy_wc}}</text>
				        <text>/{{item.zy_total}}</text>
				        <text class='fu-iconfont2  fd2_0_c1_c4_ibhf'>&#xe7f2;</text>
				    </view>
				    <image class='fd2_0_c2_ibhf' mode="aspectFit" :src='STATIC_URL+"1608.png"' @tap="aianalyse(item.knowledgepoints_id,item.knowledgepoints_title,index)"></image>
				</view>
				<!-- 	<view class='flex flex-direction flex-wrap align-stretch prepare_fd2_0' v-for="(item,index) in list" :key="index" v-if="list.length>0 && isup">
					<view class='flex flex-wrap align-center prepare_fd2_0_c0'>
						<text class='prepare_fd2_0_c0_c0'>{{$t('知识点一：')}}</text>
						<text class='prepare_fd2_0_c0_c1'>{{item.knowledgepoints_title}}</text>
						<image class='prepare_fd2_0_c0_c2' mode="aspectFit" :src='STATIC_URL+"1608.png"'
							@tap="aianalyse(item.knowledgepoints_id,item.knowledgepoints_title,index)"></image>
						<text class="zt" @tap.stop="jump(item)">查看资源</text>
					</view>
					<view class="jd"> 查看资源进度：{{item.zy_wc}}/{{item.zy_total}}</view>
					<view class='flex flex-wrap align-center justify-between prepare_fd2_0_c1 borderbottom'>
						<view class='flex flex-wrap align-center'>
							<text class='prepare_fd2_0_c1_c0_c0'>{{$t('难易程度')}}</text>
							<view class='flex flex-wrap align-center'>
								<template v-for="starNum in [1,2,3,4,5]">
									<image v-if="item.ny >= starNum" :key="starNum" class='prepare_star1fd2_0_c1_c0_c1'
										mode="aspectFit" :src='STATIC_URL+"428.png"'></image>
									<image v-else :key="starNum" class='prepare_star1fd2_0_c1_c0_c1' mode="aspectFit"
										:src='STATIC_URL+"294.png"'></image>
								</template>
							</view>
						</view>
						<view class='flex flex-wrap align-center'>
							<text class='prepare_fd2_0_c1_c0_c0'>{{$t('掌握程度')}}</text>
							<view class='flex flex-wrap align-center'>
								<template v-for="starNum in [1,2,3,4,5]">
									<image v-if="item.mastery_level >= starNum" :key="starNum"
										class='prepare_star1fd2_0_c1_c1_c1' mode="aspectFit"
										:src='STATIC_URL+"428.png"'></image>
									<image v-else :key="starNum" class='prepare_star1fd2_0_c1_c0_c1' mode="aspectFit"
										:src='STATIC_URL+"294.png"'></image>
								</template>
							</view>
						</view>
					</view>
					<view class='flex flex-wrap align-center justify-between prepare_fd2_0_c1' style="margin-top: 24rpx;">
						<view class='flex flex-wrap align-center'>
							<text class='prepare_fd2_0_c1_c0_c0'>学习资源</text>
							
						</view>
						<view class='flex flex-wrap align-center' @tap.stop="jump(item)">
							<text class='prepare_fd2_0_c1_c0_c0'>学习进度：{{item.zy_wc}}/{{item.zy_total}}</text>
							<text class='fu-iconfont2'>&#xe7f2;</text>
						</view>
					</view>
					<view class='flex flex-wrap align-center prepare_fd2_0_c2' v-if="item.show">
						<view class='flex flex-wrap align-center flex-sub prepare_fd2_0_c1'>
							<text class='prepare_fd2_0_c2_c0_c0'>{{$t('AI分析：')}}</text>
							<view class="close" v-if="item.analyse" @tap.stop="checkopen(index)">
								<text class='fu-iconfont2 ' v-if="item.isopen">&#xe78a;</text>
								<text class='fu-iconfont2 ' v-else>&#xe7ed;</text>
							</view>
						</view>
						<u-loading-icon style="margin: 0 280rpx 0 0; width: 80rpx;" :show="item.show&&!item.analyse">
						</u-loading-icon>
						<view class='prepare_fd2_0_c2_c1' :class="item.isopen?'hid1':''" v-if="item.analyse"
							v-html="item.analyse"></view>
					</view>
				</view> -->
				<view v-if="list.length==0 && isup">
					<slot>
						<view class="public-page-empty">
							<image src='/static/global/order.png'></image>
							<view class="txt">暂无数据</view>
						</view>
					</slot>
				</view>
			</view>
			
			<!---flex布局flex布局结束-->
			<view class="flex benben-position-layout flex flex-wrap align-center prepare_flex_4"
				:style="{height:(110+bottomSafeAreaRpx)+'rpx',paddingBottom:bottomSafeAreaRpx+'rpx', }">
				<button class='prepare_fd4_0' @click="navs">{{$t('预习测试')}}</button>
			</view>
			<!-- <view :style="{height: (88+bottomSafeAreaRpx)+'rpx'}"></view> -->
			<benben-popup v-model="popupShow1762237527381" :mask="true" :mask-close-able="true" mode='center' :z-index='999'>
			    <!---flex布局2flex布局开始-->
			    <view class="flex flex-direction flex-wrap align-stretch benben-flex-layout flex_1_ibhf">
			        <view class='flex flex-wrap align-center justify-center fd1_0_ibhf'>
			            <text class='fd1_0_c0_ibhf'>AI分析</text>
			            <!-- <text class='fu-iconfont2  fd1_0_c1_ibhf'>&#xE748;</text> -->
			        </view>
					<view style="text-align: center;margin-top: 64rpx;" v-if="!analyse">
						<image style="width: 156rpx;height: 156rpx;" src="/static/images/AI.gif" mode=""></image>
						<view>分析中...</view>
					</view>
					<view v-else class="fd1_1_ibhf" v-html="analyse"> </view>
			      <!--  <scroll-view class='fd1_1_ibhf' :scroll-x='false' :scroll-y='true' :show-scrollbar='false' :enhanced="true">
			            <view class='flex benben-scroll flex align-center' v-html="analyse">
							
			            </view>
			        </scroll-view> -->
			
			    </view>
			
			    <!---flex布局2flex布局结束-->
			
			</benben-popup>

		</view>
	</page-body>
</template>
<script>
	import {
		mdToHtml
	} from '@/common/utils/mdParser.js'
	export default {
		components: {},


		data() {
			return {
				index:0,
				isup:false,
				"tabsInfofd1_0": {
					lineleft: '',
					lineWidth: '',
					moveX: 0,
					scrollX: 0,
					PageScrollX: 0,
					isInit: false
				},
				"tab": "1",
				"fd2_0_c1_c0_c1": 2,
				"fd2_0_c1_c1_c1": 2,
				"fd2_1_c1_c0_c1": 2,
				"fd2_1_c1_c1_c1": 2,
				"analyse": "",

				"classname": "",
				"classhourName": "",
				"datum": "",
				"aid": "687",
				aid: "",
				list: [],
				name: '', //课程名称
				name2: '', //课前预习名称
				aid: '', //作业记录id
				homeid: '', //作业库id
				popupShow1762237527381:false,
			};
		},
		computed: {

		},
		watch: {},
		onLoad(options) {
			let {
				id,
				name,
				name2
			} = options
			if (id != undefined) this.aid = id
			if (name2 != undefined) this.classhourName = name2
			if (name != undefined) this.classname = name
			this.homeworkreleaserecord_id = options.homeworkreleaserecord_id
			this.homeid = options.homeid
			console.log(this.name2)
			// if (aid != undefined) this.aid = aid
			this.get6690ebae3b794(1)
		},
		onUnload() {

		},
		onReady() {

		},
		onShow() {
			
		},
		onHide() {

		},
		onResize() {

		},
		onPullDownRefresh() {

		},
		onReachBottom(e) {

		},
		onPageScroll(e) {

		},
		methods: {
			// ai分析
			aianalyse(id, name, index) {
				// this.list.forEach(item => {
				// 	item.show = false
				// 	if (item.knowledgepoints_id == id) {
				// 		item.show = true
				// 	}
				// })
				// console.log(this.list)
				this.analyse = ""
				this.popupShow1762237527381=true
				this.get662c96aab794d(name, index)
				this.$forceUpdate()
			},

			async get662c96aab794d(name, index) {
				
				let data662c96aab794d = await this.$api.post(global.apiUrls.post68c910fcdbef9, {
					agent_id: '62',
					query: `针对一名学生，在进行课前预习时，请针对课程【${this.classname}】内【${this.classhourName}】下的【${name}】进行分析，指导学生进行预习`
				})
				if (data662c96aab794d.data.code != 1) {
					this.$message.info(data662c96aab794d.data.msg);
					return
				}
				let info662c96aab794d = data662c96aab794d.data.data
				// this.list[index].analyse = mdToHtml(info662c96aab794d.answer)
				// this.list[index].isopen = true
				// this.list[index].show=true
				this.analyse =  mdToHtml(info662c96aab794d.answer)
				
				this.$forceUpdate()
			},
			// 获取课前预习知识点
			async get6690ebae3b794() {
				let data6690ebae3b794 = await this.$api.get(global.apiUrls.post68cbd5d51c6e7, {
					homework_id: this.homeid
				})
				this.isup=true
				if (data6690ebae3b794.data.code != 1) {
					this.$message.info(data6690ebae3b794.data.msg);
					return
				}
				let info6690ebae3b794 = data6690ebae3b794.data.data
				console.log("data6690ebae3b794=>", info6690ebae3b794)
				this.list = info6690ebae3b794
				this.list.forEach(item => {
					item.isopen = false
					item.analyse = ''
					item.show = false
					item.ny = item.difficulty == 'beginner' ? 1 : item.difficulty == 'intermediate' ? 3 : 5
				})
			},

			// 展开合上
			checkopen(index) {
				this.list[index].isopen = !this.list[index].isopen
				this.list.splice(index, 1, this.list[index])
				console.log(this.list)
			},

			// 预习测试
			async navs() {
				// // 查看预习测试有没有发布
				// let res = await this.$api.post(global.apiUrls.post669e09ab2af21, {
				// 	teaching_id: this.aid,
				// 	type: 1
				// })

				// if (res.data.code != 1) {
				// 	this.$message.info(res.data.msg);
				// 	return
				// }

				uni.redirectTo({
					url: "/pages/kc/answer/answer?homeid=" + this.homeid + '&homeworkreleaserecord_id=' + this.homeworkreleaserecord_id
				})
			},
			
			jump(item){
				uni.navigateTo({
					url:'/pages/kc/zjzy/zjzy?aidList='+item.knowledgepoints_id+'&type=2'
				})
			}
		}
	};
</script>
<style lang="scss" scoped>
	.tab-outer {
		z-index: 99;
	}

	.page {
		width: 100vw;
		height: calc(100vh - var(--window-bottom));
		background: #F8F8F8;
		background-size: 100% auto;
		overflow: hidden;
		position: relative;
	}
	.MyPortrayal_fd1_0_c0_c1 {
		color: #333;
		font-size: 32rpx;
		font-weight: 500;
		line-height: 48rpx;
		margin: 0rpx 0rpx 0rpx 10rpx;
	}
	.MyPortrayal_fd1_0_c0_c0 {
		width: 120rpx;
		height: 10rpx;
		background: linear-gradient(90deg, rgba(20, 94, 253, 0) 0%, #145EFD 100%);
		border-radius: 0px 0px 0px 0px;
		margin-top: -20rpx;
		margin-left: 40rpx;
	}

	.prepare_linefd1_0 {
		background: #145efd;
		width: 50rpx;
		height: 8rpx;
		top: 80rpx;
		background-size: 100% auto !important;
	}

	.checkTitlefd1_0 {
		font-weight: 700 !important;
		font-size: 28rpx !important;
		color: #333 !important;
	}

	::v-deep .prepare_benbenTabsfd1_0 {
		width: 750rpx;
		height: 90rpx;
		white-space: nowrap;
		text-align: center;
	}

	.prepare_flex_2 {
		padding: 15rpx 24rpx 32rpx 24rpx;
		height: calc(100vh - 258rpx);
		overflow: hidden;
		overflow-y: auto;
	}

	::v-deep .prepare_fd2_0_c2_c1 {
		width: 100%;
	}

	.prepare_fd2_0_c2_c0_c0 {
		color: rgba(20, 94, 253, 1);
		line-height: 40rpx;
		font-weight: 500;
		font-size: 28rpx;
	}

	.close {
		margin-left: auto;
	}

	.fu-iconfont2 {
		font-size: 20rpx;
		color: #333333;
	}

	.prepare_fd2_0_c2 {
		background: #f3f6f8;
		background-size: 100% auto;
		border-radius: 16rpx;
		padding: 24rpx;
	}

	.prepare_star1fd2_0_c1_c1_c1 {
		width: 24rpx;
		height: 24rpx;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
		margin: 0rpx 5rpx 0rpx 5rpx;
	}

	.prepare_star1fd2_0_c1_c0_c1 {
		height: 24rpx;
		margin: 0rpx 5rpx 0rpx 5rpx;
		width: 24rpx;
	}

	.prepare_star1fd2_0_c1_c0_c1 {
		width: 24rpx;
		height: 24rpx;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
		margin: 0rpx 5rpx 0rpx 5rpx;
	}
	.jd{
		color:#999999 ;
		font-size: 24rpx;
		margin-bottom: 24rpx;
	}

	.prepare_fd2_0_c1_c0_c0 {
		margin: 0rpx 16rpx 0rpx 0rpx;
		color: rgba(153, 153, 153, 1);
		font-size: 24rpx;
	}

	.prepare_fd2_0_c1 {
		padding: 0rpx 0rpx 24rpx 0rpx;
	}
	.borderbottom{
		border-bottom: 1rpx solid #f5f5f5;
	}

	.prepare_fd2_0_c0_c2 {
		width: 28rpx;
		height: 28rpx;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
	}

	.zt {
		margin-left: auto;
		width: 92rpx;
		height: 40rpx;
		line-height: 40rpx;
		text-align: center;
		background: #F4F8FD;
		background-size: 100% auto;
		border-radius: 12rpx;
		font-size: 24rpx;
		color: #1C5EFC;
		padding: 0 10rpx;


	}

	.prepare_fd2_0_c0_c1 {
		color: #333;
		font-size: 28rpx;
		font-weight: 500;
		line-height: 48rpx;
		margin: 0rpx 16rpx 0rpx 0rpx;
	}

	.prepare_fd2_0_c0_c0 {
		color: #333;
		font-size: 28rpx;
		font-weight: 500;
		line-height: 48rpx;
	}

	.prepare_fd2_0_c0 {
		margin: 0rpx 0rpx 18rpx 0rpx;
	}

	.prepare_fd2_0 {
		background: var(--benbenbgColor1);
		margin: 0rpx 0rpx 24rpx 0rpx;
		border-radius: 16rpx;
		background-size: 100% auto;
		padding: 32rpx 24rpx 32rpx 24rpx;
	}




	.prepare_flex_4 {
		width: 750rpx;
		height: 110rpx;
		overflow: hidden;
		z-index: 10;
		bottom: calc(0rpx + var(--window-bottom));
		left: 0rpx;
		border-radius: 0rpx;
	}

	.prepare_fd4_0 {
		background: #4781f5;
		width: 100%;
		line-height: 110rpx;
		font-size: 32rpx;
		color: #fff;
		border-radius: 0rpx;
	}

	.flex_0_ibhf {
		width: 750rpx;
		height: 88rpx;
		overflow: hidden;
		z-index: 10;
		top: 0rpx;
		background: #fff;
		background-size: 100% auto !important;

		.fd0_0_ibhf {
			padding: 0rpx 32rpx 0rpx 32rpx;

			.fd0_0_c1_c0_ibhf {
				font-size: 36rpx;
				font-weight: 700;
				color: #333333;
				line-height: 50rpx;
			}
		}
	}

	.fd0_0_c0_ibhf {
		width: 120rpx;

		.fd0_0_c0_c0_ibhf {
			font-size: 36rpx;
			color: #333;
		}
	}
	::v-deep .benbenTabsfd1_0_ibhf {
		width: 750rpx;
		height: 90rpx;
		white-space: nowrap;
		background: #fff;
		text-align: center;
	}
	.checkTitlefd1_0_ibhf {
		font-weight: 700 !important;
		font-size: 28rpx !important;
		color: #333 !important;
		background-color: rgba(255, 255, 255, 1) !important;
	}
	.linefd1_0_ibhf {
		width: 40rpx;
		height: 8rpx;
		top: 80rpx;
		background: #145efd;
		background-size: 100% auto !important;
		border-radius: 4rpx;
	}
	
	.public-page-empty {
			  display: flex;
			  justify-content: center;
			  flex-direction: column;
			  align-items: center;
			  padding: 120upx 0 0 0;
			  image {
			    width: 300rpx;
			    height: 300rpx;
			  }
			
			  .txt {
			    font-size: 28upx;
			    color: $uni-text-color;
			    text-align: center;
			    line-height: 100upx;
			    color: var(--benben-loading-color, #999999);
			  }
			  .loadTips {
			    line-height: 30upx;
			  }
			
			  .btn {
			    width: 260upx;
			    height: 78upx;
			    line-height: 78upx;
			    background: linear-gradient(309deg, rgba(254, 49, 0, 1) 0%, rgba(255, 90, 16, 1) 100%);
			    opacity: 1;
			    border-radius: 44upx;
			    font-size: 28upx;
			    color: #fff;
			    text-align: center;
			    margin-top: 100upx;
			  }
			}
	
	.fd2_0_ibhf {
	    background: url(image-path('23.png')) no-repeat;
	    background-size: 100% auto;
	    height: 319rpx;
	    padding: 30rpx 40rpx 0rpx 40rpx;
	    position: relative;
		margin-bottom: 24rpx;
	    .fd2_0_c0_ibhf {
	        border-bottom: 1px solid #eee;
	        width: 100%;
	
	        .fd2_0_c0_c0_c0_ibhf {
	            color: #333333;
	            font-size: 32rpx;
	            font-weight: 400;
	            line-height: 48rpx;
	            text-align: left;
	            font-style: normal;
	            margin: 0rpx 0rpx 32rpx 0rpx;
	        }
			 .fd2_0_c0_c1_ibhf {
			            margin: 0rpx 0rpx 24rpx 0rpx;
			            color: rgba(102, 102, 102, 1);
			            font-size: 24rpx;
			        }
					.star1fd2_0_c0_c1_c1_c0_ibhf {
					    height: 28rpx;
					    margin: 0rpx 5rpx 0rpx 5rpx;
					    width: 28rpx;
					}
	    }
	
	    .fd2_0_c1_ibhf {
	        height: 88rpx;
	        margin: auto 0rpx 0rpx 0rpx;
	        font-size: 24rpx;
	        color: rgba(102, 102, 102, 1);
	
	        .fd2_0_c1_c1_ibhf {
	            margin: 0rpx 0rpx 0rpx auto;
	            color: rgba(19, 29, 52, 1);
	            font-weight: 400;
	        }
	
	        .fd2_0_c1_c2_ibhf {
	            color: rgba(20, 94, 253, 1);
	        }
	
	        .fd2_0_c1_c4_ibhf {
	            font-size: 24rpx;
	        }
	    }
	
	    .fd2_0_c2_ibhf {
	        width: 64rpx;
	        height: 64rpx;
	        border-radius: 0rpx;
	        position: absolute;
	        top: 84rpx;
	        right: 40rpx;
	    }
	}
	.flex_1_ibhf {
	    width: 80vw;
	    margin: 0rpx auto 0rpx auto;
	    height: 30vh;
	    background: var(--benbenbgColor1);
	    background-size: 100% auto;
	    border-radius: 16rpx;
	
	    .fd1_0_ibhf {
	        line-height: 88rpx;
	
	        .fd1_0_c0_ibhf {
	            // margin: 0rpx 0rpx 0rpx auto;
	            font-size: 32rpx;
	        }
	
	        .fd1_0_c1_ibhf {
	            margin: 0rpx 0rpx 0rpx auto;
				margin-right: 24rpx;
	        }
	    }
	
	    .fd1_1_ibhf {
			padding: 24rpx;
	       width: 100%;
		   height: 380rpx;
		   overflow-y: auto;
	    }
	}
</style>
